package cn.cleanarch.infra.idp.pms.dao.repository;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.cleanarch.infra.idp.pms.dao.mapper.DesignFileMapper;
import cn.cleanarch.infra.idp.pms.domain.entity.DesignFile;
import cn.cleanarch.infra.idp.pms.domain.query.DesignFileQuery;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 设计文件Repository类
 */
@Component
public class DesignFileRepository extends ServiceImpl<DesignFileMapper, DesignFile> implements IService<DesignFile> {
    
    /**
     * 分页查询设计文件
     * @param query 查询参数
     * @return 分页结果
     */
    public Page<DesignFile> pageQuery(DesignFileQuery query) {
        return this.baseMapper.pageQuery(new Page<>(query.getPageNo(), query.getPageSize()), query);
    }

    /**
     * 根据ID获取设计文件详情(包含标签)
     * @param id 文件ID
     * @return 设计文件详情
     */
    public DesignFile getDetailById(Long id) {
        return this.baseMapper.getDetailById(id);
    }

    /**
     * 根据文件ID获取标签ID列表
     * @param fileId 文件ID
     * @return 标签ID列表
     */
    public List<Long> getTagIdsByFileId(Long fileId) {
        return this.baseMapper.getTagIdsByFileId(fileId);
    }

    /**
     * 批量删除文件与标签的关联
     * @param fileId 文件ID
     */
    public void deleteTagRelationsByFileId(Long fileId) {
        this.baseMapper.deleteTagRelationsByFileId(fileId);
    }

    /**
     * 批量保存文件与标签的关联
     * @param fileId 文件ID
     * @param tagIds 标签ID列表
     */
    public void saveTagRelations(Long fileId, List<Long> tagIds) {
        this.baseMapper.saveTagRelations(fileId, tagIds);
    }
}
